package main

import (
	"yuanxin-admin/internal/common/auth"
	"yuanxin-admin/internal/common/ioc"
	"yuanxin-admin/router"

	_ "yuanxin-admin/internal/logic"
	"yuanxin-admin/internal/repository"

	"gitee.com/botaoshow/yuanxin"
	"gitee.com/botaoshow/yuanxin/web/common/database"
	"gitee.com/botaoshow/yuanxin/web/common/redis"
	"github.com/gin-gonic/gin"
)

// gd 生成数据库模型
func gd() {
	database.DaoGenerator("./internal/repository")
}

// runApp 运行程序
func runApp() {
	ioc.InitIocContainer()
	var eg *gin.Engine
	yuanxin.OnStart(func() {
		database.InitMysql()
		repository.SetDefault(database.Db)
		redis.InitRedis()
		auth.InitAuth(eg)
	})
	yuanxin.OnClose(func() {
		database.CloseMysql()
		redis.Close()
	})
	yuanxin.RunApp(func(r *gin.Engine) {
		eg = r
		router.SetupRouter(r)
	})
}

func main() {
	runApp()
}
